home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / scriptclientinterface.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  4.3 KB  |  125 lines

  1. /* This file is part of the KDE project
  2.    Copyright (C) 2001 Ian Reinhart Geiser  (geiseri@kde.org)
  3.  
  4.    This library is free software; you can redistribute it and/or
  5.    modify it under the terms of the GNU Library General Public
  6.    License as published by the Free Software Foundation; either
  7.    version 2 of the License, or (at your option) any later version.
  8.  
  9.    This library is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.    Library General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU Library General Public License
  15.    along with this library; see the file COPYING.LIB.  If not, write to
  16.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17.    Boston, MA 02110-1301, USA.
  18. */
  19. #ifndef __scriptclientinterface_h__
  20. #define __scriptclientinterface_h__
  21. #include <qvariant.h>
  22.  
  23. class QString;
  24.  
  25. //namespace KScriptInterface
  26. //{
  27.     /**
  28.     *    This class is used for allowing feedback to the main system.
  29.     *    @author Ian Reinhart Geiser <geiseri@kde.org>
  30.     *
  31.     *    To implement KScript in your application you would use this class to interface with the scripting engine.
  32.     *    There are currently a few implementations of script managers around but developers can implement their own custom
  33.     *    interfaces with this class.
  34.     * @code
  35.     *    class MyScript : public QObject, public KScriptClientInterface {
  36.     *    Q_OBJECT
  37.     *    public:
  38.     *
  39.     *    MyScript(QObject *parent)
  40.     *    {
  41.     *        // Create your @ref KScriptInterface here.
  42.     *        m_interface = KParts::ComponentFactory::createInstanceFromQuery<KScriptInterface>( 
  43.     *            "KScriptRunner/KScriptRunner", "([X-KDE-Script-Runner] == 'bash/shell')", this );
  44.     *    }
  45.     *
  46.     *    virtual ~KScriptAction()
  47.     *    {
  48.     *        delete m_interface;
  49.     *    }
  50.     *
  51.     *    signals:
  52.     *    void error ( const QString &msg );
  53.     *    void warning ( const QString &msg );
  54.     *    void output ( const QString &msg );
  55.     *    void progress ( int percent );
  56.     *    void done ( KScriptClientInterface::Result result, const QVariant &returned );
  57.     *
  58.     *    public slots:
  59.     *    void activate(const QVariant &args)
  60.     *    {
  61.     *        m_interface->run(parent(), args);
  62.     *    }
  63.     *
  64.     *    private:
  65.     *
  66.     *    KScriptInterface *m_interface;
  67.     *    };
  68.     * @endcode
  69.     *    Things to note about this example are that it only handles a single script type and instance.  You may wish to
  70.     *    extend this.  
  71.     **/
  72.  
  73.     class KScriptClientInterface
  74.     {
  75.     public:
  76.         enum Result { ResultSuccess, ResultFailure, ResultContinue, ResultBreak };
  77.         /**
  78.         *    This function will allow the main application of any errors
  79.         *    that have occurred during processing of the script.
  80.         *    For script clients its best to implement this as a signal so feedback
  81.         *    can be sent to the main application.
  82.         */
  83.         virtual void error( const QString &msg ) =0;
  84.         /**
  85.         *    This function will allow the main application of any warnings
  86.         *    that have occurred during the processing of the script.
  87.         *    For script clients its best to implement this as a signal so feedback
  88.         *    can be sent to the main application.
  89.         */
  90.         virtual void warning( const QString &msg ) =0;
  91.         /**
  92.         *    This function will allow the main application of any normal
  93.         *    output that has occurred during the processing of the script.
  94.         *    For script clients its best to implement this as a signal so feedback
  95.         *    can be sent to the main application.
  96.         */
  97.         virtual void output( const QString &msg ) =0;
  98.         /**
  99.         *    This function will allow feedback to any progress bars in the main
  100.         *    application as to how far along the script is.  This is very useful when
  101.         *    a script is processing files or doing some long operation that is of a
  102.         *    known duration.]
  103.         *    For script clients its best to implement this as a signal so feedback
  104.         *    can be sent to the main application.
  105.         */
  106.         virtual void progress( int percent ) =0;
  107.         /**
  108.         *    This function will allow feedback on completion of the script.
  109.         *    It turns the result as a KScriptInteface::Result, and a return
  110.         *    value as a QVariant
  111.         *    For script clients its best to implement this as a signal so feedback
  112.         *    can be sent to the main application.
  113.         */
  114.         virtual void done( KScriptClientInterface::Result result, const QVariant &returned )  =0;
  115.         /**
  116.         *    Returned when the script has finished running.
  117.         *    For script clients its best to implement this as a signal so feedback
  118.         *    can be sent to the main application.
  119.         **/
  120.         //virtual bool isRunning() =0;
  121.     };
  122. //};
  123.  
  124. #endif
  125.